<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性</title>
</head>
<body>
<div id="example">
    <p>正常属性 {{message}}</p>
    <p>计算属性 {{reverseMessage}}</p>
</div>

<div id="app-2">
    <p>{{firstName}}</p>
    <p>{{lastName}}</p>
    <p>{{fullName}}</p>
</div>
<script type="text/javascript" src="source/vue.js"></script>
<script type="text/javascript">
    var example = new Vue({
        el: "#example",
        data: {
            message: "hello world"
        },
        computed: {
            //计算属性的getter
            reverseMessage: function () {
                //this 指向vm实例
                return this.message.split('').reverse().join('')
            }
        }
    })
    var app2 = new Vue({
        el: "#app-2",
        data: {
            firstName: "Amoi",
            lastName: "Brush"
        },
        computed: {
            fullName: {
                get: function () {
                    return this.firstName + ' ' + this.lastName
                },
                set: function (nameValue) {
                    var names = nameValue.split(' ')
                    this.firstName = names[0]
                    this.lastName = names[names.length - 1]
                }
            }
        }
    })
</script>
</body>
</html>